package com.own.business.exam.entity.vo;


import com.own.business.exam.entity.po.ExamPaper;
import com.own.business.question.entity.vo.PracticeVo;
import com.own.component.common.base.entity.vo.BaseVo;
import com.own.constant.ConstantBeanSuffix;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;

import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * ExamPaperVo
 *
 * @author chenxueli
 * @date 2021/05/18 14:43:47
 */
@Schema(title = "考试试卷表" + ConstantBeanSuffix.VO)
@Getter
@Setter
@ToString
@Accessors(chain = true)
@AllArgsConstructor
@NoArgsConstructor
public class ExamPaperVo extends BaseVo<ExamPaper> {

    @Schema(title = "试卷id")
    private Long examId;

    @Schema(title = "用户id")
    private Long userId;

    @Schema(title = "规则id")
    private Long ruleId;

    @Schema(title = "练习id")
    private Long practiceId;

    @Schema(title = "题目数量")
    private Integer questionNumber;

    @Schema(title = "作答状态 0=未作答 1=已作答 2=保存 3=废弃")
    private Integer status;

    @Schema(title = "用时（ms）")
    private Long useTime;

    @Schema(title = "分数")
    private BigDecimal score;

    @Schema(title = "提交练习的时间")
    private LocalDateTime submitTime;

    @Schema(title = "排名信息")
    private Long rank;

    @Schema(title = "练习信息")
    private PracticeVo practice;

    /**
     * 构造方法
     *
     * @param entity 原对象
     */
    public ExamPaperVo(@NonNull ExamPaper entity) {
        super(entity);
        this.examId = entity.getFkExamId();
        this.userId = entity.getFkUserId();
        this.ruleId = entity.getFkRuleId();
        this.practiceId = entity.getFkPracticeId();
        this.questionNumber = entity.getQuestionNumber();
        this.status = entity.getStatus();
        this.useTime = entity.getUseTime();
        this.score = entity.getScore();
        this.submitTime = entity.getSubmitTime();
    }

    /**
     * 转po对象
     *
     * @param entity 原
     * @return po对象
     */
    @Override
    public ExamPaper toPo(ExamPaper entity) {
        if (entity == null) {
            entity = new ExamPaper();
        }
        entity.setFkExamId(this.examId);
        entity.setFkUserId(this.userId);
        entity.setFkRuleId(this.ruleId);
        entity.setFkPracticeId(this.practiceId);
        entity.setQuestionNumber(this.questionNumber);
        entity.setStatus(this.status);
        entity.setUseTime(this.useTime);
        entity.setScore(this.score);
        entity.setSubmitTime(this.submitTime);
        return super.toPo(entity);
    }

    public void setPractice(PracticeVo practice) {
        this.practiceId = practice.getId();
        this.practice = practice;
        this.questionNumber = practice.getQuestionNumber();
        this.status = practice.getStatus();
        this.useTime = practice.getUseTime();
        this.score = practice.getScore();
        this.submitTime = practice.getSubmitTime();
    }
}
